package com.feng.exer2;

import com.feng.exer.CreateLinklist;
import com.feng.exer.CreateLinklistImpl;
import com.feng.exer.DefineNode;
import org.junit.Test;

public class test2 {
    @Test
    public void testNodes(){
        CreateLinklistImpl linklist = new CreateLinklistImpl();
        DefineNode node1 = new DefineNode(1001,"为什么","wsm");
        DefineNode node2 = new DefineNode(1002,"为什么呀","wsmy");
        linklist.add(node1);
        linklist.add(node2);
        OtherMethods otherMethods = new OtherMethodsImpl();
        int n = otherMethods.AllNodes(linklist);
        System.out.println("总结点数："+n);
    }

    @Test
    public void testK(){
        OtherMethods otherMethods = new OtherMethodsImpl();
        CreateLinklistImpl createLinklist = otherMethods.CREATE_LINKLIST();
        int k=2;
        DefineNode xinlang = otherMethods.Xinlang(createLinklist,k);
        if (xinlang==null){
            System.out.printf("链表总共没有%d个结点",k);
        }else {
            System.out.printf("链表中倒数第%d个结点是：",k);
            System.out.println(xinlang);
        }
    }

    @Test
    public void testK2(){
        OtherMethods otherMethods = new OtherMethodsImpl();
        CreateLinklistImpl createLinklist = otherMethods.CREATE_LINKLIST();
        int k=1;
        DefineNode xinlang = otherMethods.Xinlang2(createLinklist,k);
        if (xinlang==null){
            System.out.printf("链表总共没有%d个结点",k);
        }else {
            System.out.printf("链表中倒数第%d个结点是：",k);
            System.out.println(xinlang);
        }
    }

    @Test
    public void testTencent(){
        OtherMethods otherMethods = new OtherMethodsImpl();
        CreateLinklistImpl createLinklist = otherMethods.CREATE_LINKLIST();
        System.out.println("翻转前的链表：");
        createLinklist.display();
        CreateLinklistImpl tencent = otherMethods.Tencent(createLinklist);
        System.out.println("翻转后的链表：");
        tencent.display();
    }
}
